/**
 *    Copyright (C) 2008, 2009  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef __CUBEFS_CORE_BTREE_ITERATOR_BASE_H
#define __CUBEFS_CORE_BTREE_ITERATOR_BASE_H

#include <iostream>

#include <cubefs/api/types.hpp>
#include <cubefs/core/container/container.hpp>
#include <cubefs/core/btree/names.hpp>
#include <cubefs/core/btree/macros.hpp>


namespace cubefs    {
namespace ctr       {

using namespace cubefs::btree;


CUBEFS_BTREE_ITERATOR_BASE_CLASS_NO_CTOR_BEGIN(BTreeIteratorBase)
public:
    typedef typename ModelType::NodeBase                                        NodeBase;

private:

    NodeBase*           page_;
    Int                 key_idx_;

public:
    BTreeIteratorBase(MyType &me): Base(me), me_(me), page_(NULL), key_idx_(0) {}

    void setup(const MyType &other) {
        page_       = other.page_;
        key_idx_    = other.key_idx_;

        Base::setup(other);
    }

    Int &key_idx() {
        return key_idx_;
    }

    const Int &key_idx() const {
        return key_idx_;
    }

    NodeBase* &page() {
        return page_;
    }

    const NodeBase* &page() const {
        return page_;
    }

CUBEFS_BTREE_ITERATOR_BASE_CLASS_END


//template <typename Profile, typename MyType, typename ModelType, typename ModelTypeName, typename Default>
//class TypeFactory<RootProfile, Profile, BTreeIteratorBaseFactoryName<MyType, ModelType, ModelTypeName>, Default>  {
//public:
//    typedef BTreeIteratorBase<Profile, MyType, ModelType, ModelTypeName>        Type;
//};


} //ctr
} //cubefs

#endif
